package com.sky.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author luo20
* @description 针对表【address_book(地址簿)】的数据库操作Mapper
* @createDate 2025-07-22 13:24:10
* @Entity com.sky.entity.AddressBook
*/
public interface AddressBookMapper extends BaseMapper<AddressBook> {
    /**
     * 新增地址簿
     * @param addressBook
     * @return
     */
    @Insert("insert into address_book (user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label)" +
            "values (#{userId}, #{consignee}, #{sex}, #{phone}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}, #{districtCode}, #{districtName},#{detail},#{label})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    Integer saveAddress(AddressBook addressBook);
    /**
     * 查询指定用户的所有地址
     * @param userId
     * @return
     */
    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> list(@Param("userId") Long userId);
    /**
     * 根据用户id设置地址状态
     *
     * @param addressBook
     * @return
     */
    @Update("update address_book set is_default = #{isDefault} where id = #{id}")
    Integer updDefaultStatusAddress(AddressBook addressBook);

    /**
     * 获取默认值地址
     * @param addressBook
     * @return
     */
    AddressBook getDeafaultAddress(AddressBook addressBook);

    /**
     * 根据id修改地址
     * @param addressBook
     * @return
     */
    Integer updAddressBook(AddressBook addressBook);
    /**
     * 根据地址id删除地址
     * @param id
     * @return
     */
    @Delete("delete from address_book where id = #{id}")
    Integer delAddressById(@Param("id") Integer id);


}




